package com.biscuit.page.basicservice.conf.config;

import com.google.common.collect.Multimap;
import io.minio.*;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.XmlParserException;
import io.minio.messages.Part;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.CompletableFuture;


/**
 * @author biscuit
 * @createTime 2024/7/2 19:49
 */
public class MinioClientExtend extends MinioAsyncClient {

    public MinioClientExtend(MinioAsyncClient client) {
        super(client);
    }

    // 初始化文件分片上传
    public CompletableFuture<CreateMultipartUploadResponse> initMultipartUpload(
            String bucketName, String region, String objectName,
            Multimap<String, String> headers, Multimap<String, String> extraQueryParams)
            throws InsufficientDataException, IOException, NoSuchAlgorithmException, InvalidKeyException, XmlParserException, InternalException {
        return super.createMultipartUploadAsync(bucketName, region, objectName, headers, extraQueryParams);
    }

    // 文件分片上传
    public CompletableFuture<UploadPartResponse> uploadMultipart(
            String bucketName, String region, String objectName, Object data, long length, String uploadId,
            int partNumber, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams)
            throws InsufficientDataException, IOException, NoSuchAlgorithmException, InvalidKeyException, XmlParserException, InternalException {
        return super.uploadPartAsync(bucketName, region, objectName, data, length, uploadId, partNumber, extraHeaders, extraQueryParams);
    }

    // 获取分片文件信息
    public CompletableFuture<ListPartsResponse> listMultipart(
            String bucketName, String region, String objectName, Integer maxParts,
            Integer partNumberMarker, String uploadId, Multimap<String, String> extraHeaders,
            Multimap<String, String> extraQueryParams)
            throws NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, InternalException, XmlParserException {
        return super.listPartsAsync(bucketName, region, objectName, maxParts, partNumberMarker, uploadId, extraHeaders, extraQueryParams);
    }

    // 合并分片上传文件
    public CompletableFuture<ObjectWriteResponse> mergeMultipartUpload(
            String bucketName, String region, String objectName, String uploadId,
            Part[] parts, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams)
            throws InsufficientDataException, IOException, NoSuchAlgorithmException, InvalidKeyException, XmlParserException, InternalException {
        return super.completeMultipartUploadAsync(bucketName, region, objectName, uploadId, parts, extraHeaders, extraQueryParams);
    }

}
